import { getQueryString } from '@/common/utils';

export type TXInfoOfType = {
  phone: string;
  code: string;

  certNameEnc: string;
  certNoEnc: string;

  userNameFromBoss: string;
  certNumFromBoss: string;
};

const CardReSold = {
  state: {
    TXInfo: {
      // 通信验证信息
      phone: '',
      code: '',

      // 实名上传信息
      certNoEnc: '',
      certNameEnc: '',
      identity1: '',
      identity2: '',
      crown: '',
      checkDesc: '',
      recordId: getQueryString('recordId')
    }
  },
  reducers: {
    updateTXInfoAction(state: any, payload: any) {
      return { ...state, TXInfo: { ...state.TXInfo, ...payload } };
    },
    clearTXInfoAction(state: any) {
      return { ...state, TXInfo: {} };
    }
  },
  effects: (dispatch: any) => ({
    async updateTXInfo(payload: any, rootState: any) {
      return await new Promise<void>(resolve => {
        dispatch.CardReSold.updateTXInfoAction(payload);
        resolve();
      });
    },
    async clearTXInfo() {
      return await new Promise<void>(resolve => {
        dispatch.CardReSold.clearTXInfoAction();
        resolve();
      });
    }
  })
};

export default CardReSold;
